<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MvcContrib.FluentHtml.ModelViewPage<Universum.Views.QuestionIt.QuestionIndexViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Universum - Question IT
</asp:Content>
<asp:Content ID="BreadcrumbsContent" ContentPlaceHolderID="Breadcrumbs" runat="server">
	<%= Html.Breadcrumb().Home().AppendText("Question IT").End() %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

	<div class="span-22">
	<% if (Html.IsSpecialUserLoggedIn().IsFalse())
	{ %>
		<ul class="question-menu">
			<li>
				<%=Html.ActionLink<QuestionItController>(c => c.Create(), "Ask a question")%></li>
			<li>
				<%=Html.ActionLink<QuestionItController>(c => c.Unanswered(1), "Unanswered")%></li>
			<li>
				<%=Html.ActionLink<QuestionItController>(c => c.Answered(1), "Answered")%></li>
			<li>
				<%=Html.ActionLink<QuestionItController>(c => c.Hottest(1), "Hottest")%></li>
		</ul>
		<% } %>
	</div>
	<div class="span-22">
		<% 
			if (Model.QuestionsCount > 0)
				foreach (var item in Model.Questions)
				{
					Html.RenderPartial("DisplayUC", item);
				}
			else
			{
				%>
				<p>There are no 
				<%
					if (Html.IsSpecialUserLoggedIn())
					{
						%> offensive <%
					}
				 %>
				
				 questions to display at this time</p>
				<%
			}
		%>
	</div>
	<div class="span-22">
		<%= Html.Pager<QuestionItController>(c => c.Index(0),
			Model.QuestionsPerPage,
				Model.StartIndex,
					Model.QuestionsCount)
		%>
	</div>
	<div id="dialog" title="Remove question?">
		<p>
			<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
			This question will be permanently removed.
			<br />
			Are you sure you want to continue?</p>
	</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
	<link rel="Stylesheet" type="text/css" href="<%= Html.ResolveUrl("~/content/css/start/ui.css") %>" />
<script type="text/javascript" src="<%= new ContentDirectoryService("scripts/jqueryui.js").Path %>"></script>
	<script type="text/javascript" language="javascript">
		function attach_offensive_question_handlers() {
			$(".offensive-question-link").click(function() {
				var parrent_id = $(this).closest(".question").attr("id");

				$(".marked-offensive-" + parrent_id).html("<small class=\"offensive\"><center>marked offensive</center></small>");
				$(this).removeClass("offensive-question-link").addClass("unoffensive-question-link");
				$.post($(this).attr("href"),"asdf");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("Mark", "UnMark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_question_handlers();
				return false;
			});
			$(".unoffensive-question-link").click(function() {
				var parrent_id = $(this).closest(".question").attr("id");

				$(".marked-offensive-" + parrent_id).html("");
				$.post($(this).attr("href"),"asdf");
				$(this).removeClass("unoffensive-question-link").addClass("offensive-question-link");
				var attr_href = $(this).attr("href");
				attr_href = attr_href.replace("UnMark", "Mark");
				//alert(attr_href);
				$(this).attr("href", attr_href);
				$(this).unbind("click");
				attach_offensive_question_handlers();
				return false;
			});
			
		}
		$(function() {
			attach_offensive_question_handlers();
			$(".delete-question-link").click(function() {
				var the_link = $(this);
				var parent_question = $(this).closest("div.question");
				$("#dialog").dialog('option', 'buttons', {
					'Remove this question for real?': function() {
						$.post(the_link.attr("href"),"asdf");
						parent_question.remove();
						$(this).dialog('close');
					},
					Cancel: function() {
						$(this).dialog('close');
					}
					// buttons
				}); // dialog
				$("#dialog").dialog('open');
				return false;

			}); // delete question link

			$("#dialog").dialog({
				autoOpen: false,
				bgiframe: true,
				resizable: false,
				height: 140,
				width: 400,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			}); // dialog

		});                 // document load
	</script>

</asp:Content>
